package cn.tjie.basic.controller;

import cn.tjie.basic.dto.LoginDto;
import cn.tjie.basic.exception.BusinessException;
import cn.tjie.basic.util.AjaxResult;
import cn.tjie.basic.util.FastDfsUtils;
import cn.tjie.user.service.ILogininfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * 登录接口
 */
@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private ILogininfoService logininfoService;
    @PostMapping("/account")
    public AjaxResult account(@RequestBody LoginDto loginDto){
        try {

            Map<String,Object> map = logininfoService.account(loginDto);
            AjaxResult ajaxResult = new AjaxResult();
            ajaxResult.setObj(map);
            return ajaxResult;
        } catch (BusinessException e) {
            return new AjaxResult(false,e.getMessage());
        } catch (Exception e) {
            return new AjaxResult(false,"系统繁忙，请稍后重试！！！");
        }
    }
    @PostMapping("/wechat")
    public AjaxResult wechatLogin(@RequestBody Map<String,String> map){
        try {
            return logininfoService.wechatLogin(map);

        } catch (Exception e) {
            return new AjaxResult(false,"系统繁忙，请稍后重试！！！");
        }
    }

    @PostMapping("/wechat/binder")
    public AjaxResult binder(@RequestBody Map<String,String> map){
        try {
            return logininfoService.wechatBinder(map);
        } catch (BusinessException e) {
            return new AjaxResult(false,e.getMessage());
        } catch (Exception e) {
            return new AjaxResult(false,"系统繁忙，请稍后重试！！！");
        }
    }
}